clearvars -except Globaloption option

if exist('Globaloption', 'var') == 0
    Globaloption.savefig = 1;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This code reads in the VAR dynamics and produce the Campbell-Shiller decomposition in the paper
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Load data

loaddata_4CIjoint_annual_cy_partial;

if exist('option', 'var') == 0
    option.robust = 1;
end

if option.robust == 1
    output_rp = 0.03 - mean(cy);
    filename = ['MAT/cy_UK_30'];
elseif option.robust == 2
    output_rp = 0.02 - mean(cy);
    filename = ['MAT/cy_UK_20'];
end

ttime = [startdatenum:enddatenum];


%% Estimation
run ../../tools/cs_estimation;

%% steady-state upper bound calculation
upper = exp(pxbar)*(mean(taxrevgdp-spendgdp));

if option.robust==1
    save MAT/UKprepara_30_cy.mat k0x k1x s upper pdX pxbar -regexp ^(?!(option|Globaloption)$).
elseif option.robust==2
    save MAT/UKprepara_20_cy.mat k0x k1x s upper pdX pxbar -regexp ^(?!(option|Globaloption)$).
end

%% bootstrap
run ../../tools/BS_compute;

save (filename, 's', 'std_coeff', 'gdebt', 'upper');

